"use strict"

import * as admzip from "adm-zip";

// 12345
function strendswith(s:string, t:string){
    let pos = s.lastIndexOf(t);
    if(pos == -1)
        return 0;
    return (pos == (s.length - t.length));
}

function strstartswith(s:string, t:string){
    return (s.indexOf(t) == 0);
}




let zip = new admzip("C:\\Users\\zha\\Desktop\\RSATestDoFinal.cap");
let zipEntries = zip.getEntries(); // 

zipEntries.forEach(function(zipEntry) {
        console.log(zipEntry.toString()); 
        if(strendswith(zipEntry.entryName, "/javacard/Header.cap")){
            let pos = zipEntry.entryName.lastIndexOf("/javacard/Header.cap");
            let pkgname = zipEntry.entryName.substring(0,pos);
            console.log(pkgname);
            let header_comp = zipEntry.getCompressedData();
            console.log(header_comp);
            let pkgaid = header_comp.slice(13,13+header_comp[12]);
            console.log(pkgaid);
            console.log(pkgaid.toString("hex"));
        }
        if(strendswith(zipEntry.entryName, "/javacard/Debug.cap")){
            let debug_comp = zipEntry.getCompressedData();
            console.log(debug_comp);
        }
}


